5. Referencial Integrity

Simple Explanation:

If one table (child) refers to another table’s (parent) primary key using a foreign key, referential integrity ensures that:

Example:

Parent table:

CREATE TABLE Departments (
  dept_id INT PRIMARY KEY,
  dept_name VARCHAR(100)
);

Child table:

CREATE TABLE Employees (
  emp_id INT PRIMARY KEY,
  emp_name VARCHAR(100),
  dept_id INT,
  FOREIGN KEY (dept_id) REFERENCES Departments(dept_id)
);

What Referential Integrity Does Here:

Options to Handle It: